package com.gz.controller;

import com.gz.dto.QuestionLabelDto;
import com.gz.entity.QuestionLabel;
import com.gz.service.QuestionLabelService;
import com.gz.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 题目,标签关系表(QuestionLabel)表控制层
 *
 * @author makejava
 * @since 2024-02-23 10:05:36
 */
@RestController
@RequestMapping("questionLabel")
@Api(value = "题目标签关系控制层", tags = {"题目标签关系控制层"})
public class QuestionLabelController {

  /**
   * 服务对象
   */
  @Autowired
  private QuestionLabelService questionLabelService;

  /**
   * 分页查询
   *
   * @param dto 筛选条件
   * @return 查询结果
   */
  @ApiOperation(value = "分页查询")
  @PostMapping("/queryPage")
  public R queryByPage(@RequestBody QuestionLabelDto dto, HttpServletRequest request) {
    return R.ok(questionLabelService.queryByPage(dto));
  }


  /**
   * 分页查询
   *
   * @param dto 筛选条件
   * @return 查询结果
   */
  @ApiOperation(value = "条件查询")
  @PostMapping("/queryAll")
  public R queryAll(@RequestBody QuestionLabelDto dto, HttpServletRequest request) {
    return R.ok(questionLabelService.queryAll(dto));
  }

  /**
   * 通过主键查询单条数据
   *
   * @param id 主键
   * @return 单条数据
   */
  @ApiOperation(value = "主键查询")
  @GetMapping("/queryById")
  public R<QuestionLabel> queryById(@RequestParam("id") Integer id) {
    return R.ok(questionLabelService.queryById(id));
  }

  /**
   * 新增数据
   *
   * @param questionLabel 实体
   * @return 新增结果
   */
  @ApiOperation(value = "新增数据")
  @PostMapping("/save")
  public R<QuestionLabel> add(@RequestBody QuestionLabel questionLabel) {
    return R.ok(questionLabelService.insert(questionLabel));
  }

  /**
   * 编辑数据
   *
   * @param questionLabel 实体
   * @return 编辑结果
   */
  @ApiOperation(value = "编辑数据")
  @PostMapping("/update")
  public R<QuestionLabel> edit(@RequestBody QuestionLabel questionLabel) {
    return R.ok(questionLabelService.update(questionLabel));
  }

  /**
   * 批量编辑数据
   *
   * @param list
   * @return 编辑结果
   */
  @ApiOperation(value = "批量编辑数据")
  @PostMapping("/updateBatch")
  public R<?> editBatch(@RequestBody List<QuestionLabel> list) {
    return R.ok(questionLabelService.updateBatch(list));
  }

  /**
   * 批量编辑数据
   *
   * @param list
   * @return 编辑结果
   */
  @ApiOperation(value = "批量新增数据")
  @PostMapping("/insertBatch")
  public R insertBatch(@RequestBody List<QuestionLabel> list) {
    return R.ok(questionLabelService.insertBatch(list));
  }

  /**
   * 删除数据
   *
   * @param id 主键
   * @return 删除是否成功
   */
  @GetMapping("/deleteById")
  @ApiOperation(value = "删除数据")
  public R<Boolean> deleteById(@RequestParam("id") Integer id) {
    return R.ok(questionLabelService.deleteById(id));
  }

}

